/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dds2.serviceSystem.Bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dds2.ServicesSystem.Enum.TransactionState;
import mx.its.dds2.ServicesSystem.Modelo.Profile;
import mx.its.dds2.serviceSystem.Dao.ProfileDaoLocal;

/**
 *
 * @author Carlos Asis
 */
@Stateless
public class ProfileBl implements ProfileBlLocal {

    @EJB
    private ProfileDaoLocal profileDao;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public TransactionState register(Profile profile) {
        if (profileDao.FindDuplecity(profile)) {
            return TransactionState.INCOMPLETE;
        } else {
            profileDao.create(profile);
            return TransactionState.COMPLETE;
        }

    }

    @Override
    public TransactionState modify(Profile profile) {
        if (profile.getId() == null || profileDao.find(profile.getId()) == null) {
            return TransactionState.INCOMPLETE;
        } else {
            profileDao.edit(profile);
            return TransactionState.COMPLETE;
        }
    }

    @Override
    public TransactionState delete(Profile profile) {
        if (profile.getId() == null || profileDao.find(profile.getId()) == null) {
            return TransactionState.INCOMPLETE;
        } else {
            profileDao.remove(profile);
            return TransactionState.COMPLETE;
        }
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public List<Profile> getListAll() {
        return profileDao.findAll();
    }
}
